/**
 * 
 */

$(document)
		.ready(
				function() {

					$("#message-stream-manager").show();

					/*
					 * $.ajax({ type : "GET", url : "servlet/GetRemindInfo",
					 * dateType : "json", data : "id=" + userID, success :
					 * generateReminds });
					 */

					$(".personal_links").click(
							function() {
								dropdown_click = true;
								if (already_dropdown == false) {
									$(".personal_links .dropdown").css("top",
											"40px");
									already_dropdown = true;
								} else {
									$(".personal_links .dropdown").css("top",
											"-999px");
									already_dropdown = false;
								}
							});

					$("#page").click(
							function() {
								if (already_dropdown == true
										&& dropdown_click == false) {
									$(".personal_links .dropdown").css("top",
											"-999px");
									already_dropdown = false;
								}
								dropdown_click = false;
							});

					$("#global-nav-messages").mouseover(function() {
						$("#global-nav-messages a").css("color", "#FFFFFF");
					});
					$("#global-nav-messages").mouseout(function() {
						$("#global-nav-messages a").css("color", "#BABABA");
					});

					$("#global-nav-profile").mouseover(function() {
						$("#global-nav-profile a").css("color", "#FFFFFF");
					});
					$("#global-nav-profile").mouseout(function() {
						$("#global-nav-profile a").css("color", "#BABABA");
					});

					$("#screen-name").mouseover(function() {
						$("#screen-name").css("color", "#FFFFFF");
					});
					$("#screen-name").mouseout(function() {
						$("#screen-name").css("color", "#BABABA");
					});

					$("#personal_links_setting").mouseover(function() {
						$("#personal_links_setting").addClass("active");
						$("#personal_links_setting a").css("color", "#FFFFFF");
					});
					$("#personal_links_setting").mouseout(function() {
						$("#personal_links_setting").removeClass("active");
						$("#personal_links_setting a").css("color", "#BABABA");
					});

					$("#personal_links_help").mouseover(function() {
						$("#personal_links_help").addClass("active");
						$("#personal_links_help a").css("color", "#FFFFFF");
					});
					$("#personal_links_help").mouseout(function() {
						$("#personal_links_help").removeClass("active");
						$("#personal_links_help a").css("color", "#BABABA");
					});

					$("#personal_links_signout").mouseover(function() {
						$("#personal_links_signout").addClass("active");
						$("#personal_links_signout a").css("color", "#FFFFFF");
					});
					$("#personal_links_signout").mouseout(function() {
						$("#personal_links_signout").removeClass("active");
						$("#personal_links_signout a").css("color", "#BABABA");
					});

					/*
					 * $(".stream").click( function() { var html=$(this).find(
					 * 'stream-item'); alert(id);
					 * $(".details-pane-outer").fadeIn();
					 * $(".details-pane").css("height",
					 * document.body.clientHeight - 80);
					 * $(".pane-components").css("height",
					 * document.body.clientHeight - 115); });
					 */
					$(".reply-actions a").mouseover(
							function() {
								var type = $(this).attr('rel');
								if (type == "favorite") {
									$("." + type + "-action").css(
											"background-color", "#E33100");
								} else if (type == "reply") {
									$("." + type + "-action").css(
											"background-color", "#007D9A");
								} else {
									$("." + type + "-action").css(
											"background-color", "#630030");
								}
							});

					$(".reply-actions a").mouseout(
							function() {
								var type = $(this).attr('rel');
								if (type == "favorite") {
									$("." + type + "-action").css(
											"background-color", "#FF5C00");
								} else if (type == "reply") {
									$("." + type + "-action").css(
											"background-color", "#2DAEBF");
								} else {
									$("." + type + "-action").css(
											"background-color", "#404040");
								}
							});
					/*
					 * $(".reply-action") .click( function() {
					 * $(".popup-reply-box") .css( "left",
					 * document.body.clientWidth / 2 - 250);
					 * $(".popup-reply-box") .css( "top",
					 * document.body.clientHeight / 2 - 200);
					 * $(".popup-reply-box").show(); });
					 */

					// ///////////////////////////////////////////////////////////
					// $('a.poplight[href^=#] ')
					// popup the
					box
					$(".reply-action")
							.click(
									function() {
										var popID = $(this).attr('rel'); // Get Popup  Name
										var popID="popup_name"; // Get Popup Name 
										var popURL="#?w=500" ; //Get Popup
										// href to // define size

										// Pull Query & Variables from href
										// URL var
										query = popURL.split('?');
										var dim = query[1].split('&');
										var popWidth = dim[0].split('=')[1]; // Gets
										// the first query string value

										// Fade in the Popup and add close
										// button
										$('#' + popID)
												.fadeIn()
												.css(
														{
															'width' : Number(popWidth) - 50
														})
												.prepend(
														'<a href="#" class="close"><img src="res/pic/home/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

										// Define margin for center
										// alignment (vertical horizontal) -
										// we add 80px to the height/width
										// to accomodate for the padding and
										// border width defined in the css
										var popMargTop = ($('#' + popID)
												.height() + 80) / 2;
										var popMargLeft = ($('#' + popID)
												.width() + 80) / 2;

										// Apply Margin to Popup
										$('#' + popID).css({
											'margin-top' : -popMargTop,
											'margin-left' : -popMargLeft
										});

										$(".twitter-anywhere-tweet-box-editor")
												.val(
														"@"
																+ $(
																		".details-pane-outer .reply-userfrom-username")
																		.text()
																+ " ");

										return false;
									});
					// click the reply button
					$("#reply-button")
							.click(
									function() {
										var text = $("#popup_name textarea")
												.val();
										var id = userID;
										$
												.ajax({
													type : "POST",
													url : "servlet/SetReply",
													data : "type=reply"
															+ "&id=" + id
															+ "&reply=" + text
															+ "&remindid="
															+ currentRemindId,
													success : function(msg) {
														if (msg == "success") {
															$(
																	".details-pane-outer")
																	.fadeOut();
															$("#popup_name")
																	.fadeOut();
															$(
																	"#message-stream-item-"
																			+ currentRemindId)
																	.removeClass(
																			"isotope-show");
															isotope_filter();
															jNotify(
																	"success.",
																	{
																		HorizontalPosition : "center",
																		VerticalPosition : "center"
																	});
														} else
															jError(
																	"error.",
																	{
																		HorizontalPosition : "center",
																		VerticalPosition : "center"
																	});
													}
												});
										return false;
									});

					// Close Popups and Fade Layer
					$('a.close, #fade').live('click', function() { // When
						// clicking // on // the // close // or // fade // layer...
						$('#fade , .popup_block').fadeOut(function() {
							$('#fade, a.close').remove(); // fade them
							// both out
						});
						return false;
					});
					// //////////////////////////////////////////////////////////////////////////////

					$("#reply-button").mouseover(function() {
						$(this).css("background-color", "#EEEEEE");
					});
					$("#reply-button").mouseout(function() {
						$(this).css("background-color", "#FFFFFF");
					});

					// tabs changed when click
					$(".stream-tab")
							.click(
									function() {
										var preloader = "<img src='res/pic/home/ajax_preloader.gif'>";
										var tabs = new Array("tab-message",
												"tab-groups", "tab-people",
												"tab-favorites");
										var managers = new Array(
												"message-stream-manager",
												"group-stream-manager",
												"user-stream-manager",
												"favorites-stream-manager");
										var id = $(this).attr("id");
										for (x in tabs) {
											if (tabs[x] == id) {
												$("#" + tabs[x]).addClass(
														"current-focus");
												$("#" + managers[x]).fadeIn();
												if (already_load[x] == false) {
													$(
															"#"
																	+ managers[x]
																	+ " .ajax-preloader")
															.append(preloader);
													load_new_tab(managers[x]);
												}
											} else {
												$("#" + tabs[x]).removeClass(
														"current-focus");
												$("#" + managers[x]).fadeOut();
											}
										}
										return false;
									});

				});